<?php
	
	class Mapi extends CI_Controller {

		function index(){
			$email	= $this->input->post("email");
			$nama	= $this->input->post("nama_lengkap");
			$pwd	= $this->input->post("password");
			$user	= $this->input->post("user_name");
			$key	= $this->input->post("key");
			if($key == md5("l3galisir" . date("Ydm"))){
				$config['protocol']		= 'smtp';
				$config['smtp_host']	= 'ssl://smtp.googlemail.com';
				$config['smtp_port']	= 465;
				$config['smtp_user']	= 'webmaster.legalisironline@gmail.com';
				$config['smtp_pass']	= 'l3g4lisir';
				$config['mailtype']		= 'html';
				$this->load->library('email', $config);
				$this->email->set_newline("\r\n");
				$f="http://yeavirtual.com/index.php/mapi/email?pwd=" . $pwd . "&user=" . $user . "&nama=" . $nama;
				$message= file_get_contents($f);
				$this->email->from('webmaster.legalisironline@gmail.com', 'Legalisir Online');
				$this->email->to($email);
				// $this->email->cc('tanjung@arfatech.co.id,darwin@arfatech.co.id,reklame.perijinan@gmail.com,reklame.dispenda@gmail.com');
				$this->email->subject('Konfirmasi Pendaftaran Legalisir Online');
				$this->email->message($message);
				$this->email->send();
			} else {
				echo "error";
			}
		}
		
		function send_mail()
		{
			$config['mailtype'] = 'html';
			$config['charset'] = 'utf-8';

			$config['protocol'] = 'smtp';
			$config['smtp_host'] = 'ssl://smtp.mailgun.org';
			$config['smtp_port'] = 465;
			$config['smtp_user'] = 'postmaster@energeek.co.id';
			$config['smtp_pass'] = 'energeek!@#4';
			$config['smtp_timeout'] = '4';
			$config['crlf'] = '\n';
			$config['newline'] = '\r\n';
			
			$this->load->library('email',$config);
			
			$this->email->from('postmaster@energeek.co.id', 'Legalisir Online');
			$this->email->to('erick.wp@energeek.co.id');
			$this->email->subject('Legalisir Online');
			$this->email->message('Test');
			$this->email->send();
			
			$this->email->print_debugger();
		}
		
		function email(){
			$email	= $this->input->get("email");
			$pwd	= $this->input->get("pwd");
			$user	= $this->input->get("user");
			$nama	= $this->input->get("nama");
			?>
			<html>
				<head>
					<title> Pendaftaran Legalisir Online</title>
				</head>
				<body>
					<h2>Pendaftaran Legalisir Online</h2>
					<hr>
					<p>Selamat ! Anda telah terdaftar sebagai user di website resmi Legalisir Online Dinas Pendidikan Kota Surabaya. Detail informasi yang anda kirimkan sebagai berikut : </p>
					<p>Nama Lengkap : <?php echo $nama; ?></p>
					<p>Username : <?php echo $user; ?></p>
					<p>Password : <?php echo $pwd; ?></p>
					<p>Silahkan klik <b><a href="http://202.154.13.119/legalisironline/front/activation/<?php echo md5($pwd); ?>">disini</b> untuk aktivasi akun.</p>
					<br>
					<p>Terima kasih.</p>
					<p>Salam,</p>
					<p>Admin Legalisir Online</p>
				<body>
			</html>
			<?php
		}
		
		function konfirmasi($id_pengajuan)
		{
			$name 		= $this->input->post("nama");
			$alamat 	= $this->input->post("alamat");
			$sd 		= $this->input->post("sd");
			$smp 		= $this->input->post("smp");
			$sma 		= $this->input->post("sma");
			$korektor 	= $this->input->post("korektor");	
			$ktp 		= $this->input->post("ktp");
			$ijazah1 	= $this->input->post("ijazah1");
			$ijazah2 	= $this->input->post("ijazah2");
			$ijazah3 	= $this->input->post("ijazah3");
			
			// $this->load->library('curl');
			$this->load->helper('file');
			// $img = $this->curl->simple_get("http://202.154.13.119/legalisironline/".$ktp);
			// $filename = basename($img);
			// write_file(base_url()."/thumbnail/".$filename , $img);

			// $path = "http://202.154.13.119/legalisironline/".$ktp;		

			$email	= "sekretaris.dinas@gmail.com";

			$config['protocol']		= 'smtp';
			$config['smtp_host']	= 'ssl://smtp.googlemail.com';
			$config['smtp_port']	= 465;
			$config['smtp_user']	= 'webmaster.legalisironline@gmail.com';
			$config['smtp_pass']	= 'l3g4lisir';
			$config['mailtype']		= 'html';
			$this->load->library('email', $config);
			
			// $this->email->set_newline("\r\n");
			$f	 		= "http://yeavirtual.com/index.php/mapi/email_konfirmasi?nama=" . $name ."&alamat=" . $alamat ."&sd=" . $sd ."&smp=" . $smp ."&sma=" . $sma . "&korektor=" . $korektor ."&id=".$id_pengajuan ."&ktp=". $ktp;
			$message	= file_get_contents($f);

			$this->email->from('webmaster.legalisironline@gmail.com', 'Legalisir Online');
			$this->email->to($email);
			$this->email->subject('Pengajuan berkas legalisir online');
			$this->email->message($message);
	//		$this->email->attach($path);

			if($this->email->send())
			{
				echo "success";
			}
			else
			{
				echo "error";
			}
		}

		function email_konfirmasi()
		{		
			$id		= $this->input->get("id");
			$nama		= $this->input->get("nama");
			$alamat	= $this->input->get("alamat");
			$sd		= $this->input->get("sd");
			$smp		= $this->input->get("smp");
			$sma		= $this->input->get("sma");
			$korektor	= $this->input->get("korektor");
			$ktp		= $this->input->get("ktp");
			if($korektor == 1)
			{
				$link 		= "http://202.154.13.119/legalisironline/admin/adlegalisir/konf_akhir_sekre?id=".$id;
			}
			elseif($korektor == 2)
			{
				$link = "http://202.154.13.119/legalisironline/admin/adlegalisir/konf_sekre?nama=" . $nama ."&alamat=" . $alamat ."&sd=" . $sd ."&smp=" . $smp ."&sma=" . $sma . "&korektor=" . $korektor . "&id=".$id;

			}
			?>
			<html>
				<head>
					Pengajuan legalisir online
				</head>
			<body>
				<p>Kepada Yth.</p>
				<p>Sekretaris Dinas Pendidikan Kota Surabaya</p>
				<p>di Surabaya</p>

				<p>Kami menginformasikan kepada anda mengenai berkas yang berkaitan dengan pengajuan legalisir online yang perlu anda kaji. Berikut data - data mengenai user terkait :</p>

				<p>Nama : <?php echo $nama;?> </p>
				<p>Alamat : <?php echo $alamat;?></p>
				<p>Sekolah : <?php if($sd != NULL){echo $sd.", ";}?><?php if($smp != NULL){echo $smp.", ";}?><?php if($sma != NULL){echo $sma;}?></p>

				<p>Bila data - data sudah sesuai dengan permintaaan silahkan klik <a href="<?php echo $link?>">disini</a> untuk memberikan approval. Demikian informasi yang dapat kami sampaikan.</p>

				<p>Terima Kasih,</p>
				<p>Admin Legalisir Online Dinas Pendidikan Kota Surabaya</p>
			</body>
			<script>
			function tembusan(){
				alert("Data terkirim");
			}
			</script>
			</html>
			<?php
		}

		function konfirmasi_kadin()
		{
			$id		= $this->input->get("id");
			$nama		= $this->input->get("nama");
			$alamat	= $this->input->get("alamat");
			$sd		= $this->input->get("sd");
			$smp		= $this->input->get("smp");
			$sma		= $this->input->get("sma");
			$korektor	= $this->input->get("korektor");


			$email	= "kadin.office@gmail.com";

			$config['protocol']	= 'smtp';
			$config['smtp_host']	= 'ssl://smtp.googlemail.com';
			$config['smtp_port']	= 465;
			$config['smtp_user']	= 'webmaster.legalisironline@gmail.com';
			$config['smtp_pass']	= 'l3g4lisir';
			$config['mailtype']	= 'html';
			$this->load->library('email', $config);
			$this->email->set_newline("\r\n");
			$f="http://yeavirtual.com/index.php/mapi/email_konfirmasi_kepdin?nama=" . $nama ."&alamat=" . $alamat ."&sd=" . $sd ."&smp=" . $smp ."&sma=" . $sma . "&korektor=" . $korektor."&id=".$id;
			$message= file_get_contents($f);
			$this->email->from('webmaster.legalisironline@gmail.com', 'Legalisir Online');
			$this->email->to($email);
			$this->email->subject('Pengajuan berkas legalisir online (Tembusan)');
			$this->email->message($message);
			$this->email->send();

			redirect('http://202.154.13.119/legalisironline/front/redirect_approve','refresh');
		}

		function email_konfirmasi_kepdin()
		{
			$id		= $this->input->get("id");
			$nama		= $this->input->get("nama");
			$alamat	= $this->input->get("alamat");
			$sd		= $this->input->get("sd");
			$smp		= $this->input->get("smp");
			$sma		= $this->input->get("sma");
			$korektor	= $this->input->get("korektor");
			$link 		= "http://202.154.13.119/legalisironline/admin/adlegalisir/konf_akhir_kadin?id=".$id;

			
			?>
			<html>
				<head>
					Pengajuan legalisir online
				</head>
			<body>
				<p>Kepada Yth.</p>
				<p>Bapak Kepala Dinas Pendidikan Kota Surabaya</p>
				<p>di Surabaya</p>

				<p>Kami menginformasikan kepada anda mengenai berkas yang berkaitan dengan pengajuan legalisir online yang perlu anda kaji. Berikut data - data mengenai user terkait :</p>

				<p>Nama : <?php echo $nama;?> </p>
				<p>Alamat : <?php echo $alamat;?></p>
				<p>Sekolah : <?php if($sd != NULL){echo $sd.", ";}?><?php if($smp != NULL){echo $smp.", ";}?><?php if($sma != NULL){echo $sma;}?></p>

				<p>Bila data - data sudah sesuai dengan permintaaan silahkan klik <a href="<?php echo $link?>">disini</a> untuk memberikan approval. Demikian informasi yang dapat kami sampaikan.</p>

				<p>Terima Kasih,</p>
				<p>Admin Legalisir Online Dinas Pendidikan Kota Surabaya</p>
			</body>
			</html>
			<?php
		}
		function announce_cetak(){
			$nama	= $this->input->post("nama_lengkap");
			$email	= $this->input->post("email");
			$jenkel= $this->input->post("jenkel");
			$config['protocol']	= 'smtp';
			$config['smtp_host']	= 'ssl://smtp.googlemail.com';
			$config['smtp_port']	= 465;
			$config['smtp_user']	= 'webmaster.legalisironline@gmail.com';
			$config['smtp_pass']	= 'l3g4lisir';
			$config['mailtype']	= 'html';
			$this->load->library('email', $config);
			$this->email->set_newline("\r\n");
			$f="http://yeavirtual.com/index.php/mapi/annouce_message?nama=" . $nama . "&jenkel=" . $jenkel;
			$message= file_get_contents($f);
			$this->email->from('webmaster.legalisironline@gmail.com', 'Legalisir Online');
			$this->email->to($email);
			$this->email->subject('Pemberitahuan Pengambilan Legalisir');
			$this->email->message($message);
			$this->email->send();
		}
		function annouce_message(){
		$nama = $this->input->get("nama");
		$jenkel=$this->input->get("jenkel");
		?>
		<html>
			<head>
				<title>Pemberitahuan Pengambilan Legalisir</title>
			</head>
			<body>
				<p>Kepada Yth : </p>
				<p><?php echo (($jenkel == "Laki - Laki") ? ("Sdr. ") : ("Sdri. ")); ?><?php echo $nama; ?></p>
				<p>Di Tempat</p>
				<p>Dengan ini kami menginformasikan bahwa permohonan legalisir anda telah dicetak. Silahkan mendatangi kantor Dinas Pendidikan untuk pengambilan Fotocopy Ijazah Legalisir.<br><br>Hormat kami,<br><br>Admin Legalisir Online</p>
			</body>
		</html>
		<?php
		}
	}
?>